home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / µSim 1.1 / FabLibsƒ / CursorBalloon.c < prev    next >
Encoding:
Text File  |  1997-03-06  |  5.8 KB  |  210 lines  |  [TEXT/CWIE]

  1. /*
  2. Copyright © 1993,1994 by Fabrizio Oddone
  3. ••• ••• ••• ••• ••• ••• ••• ••• ••• •••
  4. This source code is distributed as freeware: you can copy, exchange, modify this
  5. code as you wish. You may include this code in any kind of application: freeware,
  6. shareware, or commercial, provided that full credits are given.
  7. You may not sell or distribute this code for profit.
  8. */
  9.  
  10. //#pragma load "MacDump"
  11.  
  12.  
  13. #include    "UtilsSys7.h"
  14. #include    "CursorBalloon.h"
  15. #include    "FabWList.h"
  16.  
  17. static void myShowBalloon(RgnHandle theGlobalCoordsRgn,
  18.                             unsigned long theBalloon,
  19.                             short variant);
  20.  
  21. /* globals for the manager */
  22.  
  23. RgnHandle    mouseRgn, wideOpenRgn;
  24.  
  25. /*
  26. The window will "remember" an object; you pass the following characteristics:
  27. •    the region enclosing the object, in local coordinates;
  28. •    the procedure recalculating the object region (in local coordinates);
  29.     this will be called automatically whenever the window size changes;
  30.     if the object will never be resized, pass nil;
  31.     Here is the prototype for the recalcProc:
  32. void RecalcIO(WindowRef w, RgnBalloonCursPtr theObj);
  33. •    the cursor (B&W) associated with this object;
  34.     if you want the standard arrow cursor, pass nil;
  35. •    the balloon that will appear when Balloon Help is on;
  36.     use this macro: toBalloon(ID_of_STR#_resource, index );
  37.     if you do not want a balloon, pass 0L;
  38. •    the variant of the balloon (see Inside Macintosh for the meaning of this)
  39.     if you do not want a balloon, pass 0;
  40. */
  41.  
  42. OSErr InstallRgnHandler(FabWindowPtr w, RgnHandle whichRgn, void (*recalcProc)(DialogRef, RgnBalloonCursPtr),
  43.                         CursHandle cursor,
  44.                         unsigned long balloon, short ballnVariant, short iID)
  45. {
  46. RgnBalloonCurs    t;
  47. Point    mypt = { 0, 0};
  48. register OSErr err = appMemFullErr;
  49.  
  50. t.recalcRgnProc = recalcProc;
  51. t.zoneLocal = whichRgn;
  52. t.curs = cursor;
  53. t.myBalloon = balloon;
  54. t.balloonVariant = ballnVariant;
  55. t.itemID = iID;
  56. t.zoneGlobal = NewRgn();
  57. if (t.zoneGlobal) {
  58.     LocalToGlobal(&mypt);
  59.     CopyRgn(whichRgn, t.zoneGlobal);
  60.     OffsetRgn(t.zoneGlobal, mypt.h, mypt.v);
  61.  
  62.     if ((err = PtrAndHand(&t, (Handle)Zones(w), sizeof(RgnBalloonCurs))) == noErr)
  63.         OneMoreObject(w);
  64.     }
  65. return err;
  66. }
  67.  
  68. /* Recalculate the mouse region; you pass:
  69. •    a WindowPtr (not necessarily a FabWindowPtr);
  70. •    the mouse position (in global coordinates);
  71. */
  72.  
  73. void RecalcMouseRegion(DialogRef d, Point mouse)
  74. {
  75. FabWindowPtr    thefabw;
  76. RgnBalloonCursPtr    curObj;
  77. CursHandle    tempCursH;
  78. UInt32    i;
  79.  
  80. thefabw = GetFabWindowPtr(d);
  81. if (thefabw && thefabw->currentlyShowingProgressCurs == false)
  82.     if (NumObjects(thefabw)) {
  83.         CopyRgn(wideOpenRgn, mouseRgn);
  84.         HLockHi((Handle)Zones(thefabw));
  85.         for (i = 1, curObj = *Zones(thefabw); i <= NumObjects(thefabw); i++, curObj++) {
  86.             if (PtInRgn(mouse, curObj->zoneGlobal)) {
  87.                 tempCursH = curObj->curs;
  88.                 if (tempCursH)
  89.                     SetCursor(*tempCursH);
  90.                 else
  91.                     SetCursor(&qd.arrow);
  92.             //    SetCursor(tempCursH ? *tempCursH : &qd.arrow);
  93.                 if (curObj->myBalloon)
  94.                     if (HMGetBalloons())
  95.                         myShowBalloon(curObj->zoneGlobal, curObj->myBalloon,
  96.                                         curObj->balloonVariant);
  97.                 CopyRgn(curObj->zoneGlobal, mouseRgn);
  98.                 break;
  99.                 }
  100.             else
  101.                 DiffRgn(mouseRgn, curObj->zoneGlobal, mouseRgn);
  102.             }
  103.         if (i > NumObjects(thefabw))
  104.             SetCursor(&qd.arrow);
  105.         HUnlock((Handle)Zones(thefabw));
  106.         }
  107.     else {
  108.         CopyRgn(wideOpenRgn, mouseRgn);
  109.         SetCursor(&qd.arrow);
  110.         }
  111. }
  112.  
  113. /* Resizes the dynamic objects of the window by calling the recalcProc
  114. for every object */
  115.  
  116. FabWindowPtr ResizeObjects(DialogRef d)
  117. {
  118. register void (*theProc)(DialogRef, RgnBalloonCursPtr);
  119. register RgnBalloonCursPtr    curObj;
  120. register unsigned long    i;
  121. FabWindowPtr    thefabw;
  122.  
  123. if (thefabw = GetFabWindowPtr(d)) {
  124.     if (NumObjects(thefabw)) {
  125.         HLockHi((Handle)Zones(thefabw));
  126.         for (i = 1, curObj = *Zones(thefabw); i <= NumObjects(thefabw); i++, curObj++) {
  127.             theProc = curObj->recalcRgnProc;
  128.             if (theProc)
  129.                 theProc(d, curObj);
  130.             }
  131.         HUnlock((Handle)Zones(thefabw));
  132.         }
  133.     }
  134. return thefabw;
  135. }
  136.  
  137. /* Calculates the regions for the given FabWindow in global coordinates,
  138. so that they are ready for WaitNextEvent
  139. */
  140.  
  141. void RecalcGlobalCoords(FabWindowPtr w)
  142. {
  143. register RgnBalloonCursPtr    curObj;
  144. register unsigned long    i;
  145. Point    mypt = { 0, 0};
  146.  
  147. if (NumObjects(w)) {
  148.     HLockHi((Handle)Zones(w));
  149.     LocalToGlobal(&mypt);
  150.     for (i = 1, curObj = *Zones(w); i <= NumObjects(w); i++, curObj++) {
  151.         CopyRgn(curObj->zoneLocal, curObj->zoneGlobal);
  152. // -(((WindowPtr)w)->portBits.bounds.left)
  153. // -(((WindowPtr)w)->portBits.bounds.top)
  154.         OffsetRgn(curObj->zoneGlobal, mypt.h, mypt.v);
  155.         }
  156.     HUnlock((Handle)Zones(w));
  157.     }
  158. }
  159.  
  160. /* myShowBalloon: common routine for showing up balloons */
  161.  
  162. static void myShowBalloon(RgnHandle theGlobalCoordsRgn,
  163.                             unsigned long theBalloon, short variant)
  164. {
  165. HMMessageRecord    helpMsg;
  166. Point    myTip;
  167.  
  168. myTip.v = (*theGlobalCoordsRgn)->rgnBBox.top + 3;
  169. myTip.h = (*theGlobalCoordsRgn)->rgnBBox.right - 3;
  170. helpMsg.hmmHelpType = khmmStringRes;
  171. *(unsigned long *)&helpMsg.u.hmmStringRes.hmmResID = theBalloon;
  172. //helpMsg.u.hmmStringRes.hmmIndex = *(((short *)(&theBalloon)) +1);
  173. if (hmBalloonAborted == HMShowBalloon(&helpMsg, myTip, &(*theGlobalCoordsRgn)->rgnBBox,
  174.                                         nil, 0, variant, kHMRegularWindow))
  175.     ForceMouseMovedEvent();
  176. }
  177. /*
  178. void DisposFabWindow(FabWindowPtr w)
  179. {
  180. register RgnBalloonCursHandle    tempH;
  181. register RgnBalloonCursPtr    spanPtr;
  182. register unsigned long    i;
  183.  
  184. tempH = Zones(w);
  185. HLock((Handle)tempH);
  186. spanPtr = *tempH;
  187.  
  188. for (i = 0; i < NumObjects(w); i++, spanPtr++) {
  189.     DisposeRgn(spanPtr->zoneLocal);
  190.     DisposeRgn(spanPtr->zoneGlobal);
  191. // we do nothing with the CursHandles since they might be system cursors
  192.     }
  193. DisposeHandle((Handle)tempH);
  194. // the caller knows whether CloseWindow or CloseDialog is to be called
  195. }
  196.  */
  197. void ForceMouseMovedEvent(void)
  198. {
  199. SetRectRgn(mouseRgn, 32761, 32761, 32765, 32765);
  200. }
  201.  
  202. /*
  203. void InitFabWindow(FabWindowPtr w)
  204. {
  205. Zones(w) = (RgnBalloonCursHandle)NewHandle(0);
  206. if (GetWindowKind(w) != dialogKind)
  207.     SetWindowKind(w, kFabWindowClass);
  208. }
  209. */
  210.